﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AuthenticationSection
{
    public class UserInfo
    {
        public static UserInfo GetInstance { get { return new UserInfo(); } }

        public static string Identity;

        private string strRole;

        internal virtual List<UserModel> GetUsers()
        {
            List<UserModel> users = new List<UserModel>();
            UserModel user = new UserModel();
            user.UserName = "admin";
            user.PassWord = "670b14728ad9902aecba32e22fa4f6bd";
            user.Role = "1,2,3"; strRole = "1,2,3";
            users.Add(user);
            return users;
        }

        //todo 修改
        private UserInfo()
        {
            string cookie = "61'64'6D'69'6E'7C'36'37'30'62'31'34'37'32'38'61'64'39'39'30'32'61'65'63'62'61'33'32'65'32'32'66'61'34'66'36'62'64'7C'32'30'31'32'2F'32'2F'31'35'20'37'3A'34'34'3A'31'32'7C'32'30'31'32'2F'32'2F'31'35'20'38'3A'31'34'3A'31'32'7C'31'2C'32'2C'33'";
            BillsModel bills = Authentication.DecryptionBill(cookie);
            var info = GetUsers().SingleOrDefault(p => p.UserName == bills.UserName && p.PassWord == bills.Password);
            if (info != null)
            {
                Identity = bills.UserName;
            }
        }

        public bool IsRole(string role)
        {
            if (role == "" || role == null)
                return true;
            string[] roles = role.Split(',');
            string[] Roles = strRole.Split(',');
            return roles.All(p => Roles.Contains(p));
        }
    }
}
